package nc.nc_xiuxian;

import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

import static nc.nc_xiuxian.NC_XIUXIAN.plugin;

public class LINGGENG {
    public static HashMap<String,Integer> LGTFGET(Player player){
        HashMap<String,Integer>lg=new HashMap<>();
        File file0 = new File(plugin.getDataFolder(),"lg");
        if(!file0.exists()){
            file0.mkdirs();
        }
        File file = new File(file0,player.getName()+".yml");
        YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
        lg.put("lgs",yml.getInt("灵根数"));
        lg.put("lgtf",yml.getInt("灵根天赋"));
        return lg;
    }
    //灵根信息
    public static void LGLOAD(String s) throws IOException {
        File file0 = new File(plugin.getDataFolder(),"lg");
        if(!file0.exists()){
            file0.mkdirs();
        }
        File file = new File(file0,s+".yml");
        YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
        if(!file.exists()){
            file.createNewFile();
            Random random = new Random();
            int lg = random.nextInt(5) + 1;
            int tf = random.nextInt(4) + 1;
            switch (lg){
                case 1:
                    switch (random.nextInt(8) + 1){
                        case 1:
                            yml.set("灵根数",1);
                            yml.set("灵根属性","金");
                            break;
                        case 2:
                            yml.set("灵根数",1);
                            yml.set("灵根属性","木");
                            break;
                        case 3:
                            yml.set("灵根数",1);
                            yml.set("灵根属性","水");
                            break;
                        case 4:
                            yml.set("灵根数",1);
                            yml.set("灵根属性","火");
                            break;
                        case 5:
                            yml.set("灵根数",1);
                            yml.set("灵根属性","土");
                            break;
                        case 6:
                            yml.set("灵根数",1);
                            yml.set("灵根属性","风");
                            break;
                        case 7:
                            yml.set("灵根数",1);
                            yml.set("灵根属性","雷");
                            break;
                        case 8:
                            yml.set("灵根数",1);
                            yml.set("灵根属性","无");
                            break;
                    }
                case 2:
                    List<String>sx=new ArrayList<>();
                    for(int a=0;a<2;){
                        String l=lgrand();
                        if(!sx.contains(l)){
                            sx.add(l);
                            a++;
                        }
                    }
                    yml.set("灵根数",2);
                    yml.set("灵根属性",sx.get(0)+","+sx.get(1));
                    break;
                case 3:
                    sx=new ArrayList<>();
                    for(int a=0;a<3;){
                        String l=lgrand();
                        if(!sx.contains(l)){
                            sx.add(l);
                            a++;
                        }
                    }
                    yml.set("灵根数",3);
                    yml.set("灵根属性",sx.get(0)+","+sx.get(1)+","+sx.get(2));
                    break;
                case 4:
                    sx=new ArrayList<>();
                    for(int a=0;a<4;){
                        String l=lgrand();
                        if(!sx.contains(l)){
                            sx.add(l);
                            a++;
                        }
                    }
                    yml.set("灵根数",4);
                    yml.set("灵根属性",sx.get(0)+","+sx.get(1)+","+sx.get(2)+","+sx.get(3));
                    break;
                case 5:
                    yml.set("灵根数",5);
                    yml.set("灵根属性","金,木,水,火,土");
                    break;
            }
            yml.set("灵根天赋",tf);
            yml.save(file);
        }
    }

    public static String lgrand(){
        Random random = new Random();
        switch (random.nextInt(5) + 1){
            case 1:
                return "金";
            case 2:
                return "木";
            case 3:
                return "水";
            case 4:
                return "火";
            case 5:
                return "土";
        }
        return null;
    }
}
